<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
	protected function _initResourceLoader() {
		$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
				'namespace' => '',
				'basePath'  => APPLICATION_PATH
		));
        $resourceLoader->addResourceType('model', 'models/', 'Model')
                       ->addResourceType('form' , 'forms/' , 'Form')
                       ->addResourceType('grid' , 'grids/' , 'Grid');
	}

    public function _initModuleLoader() {
        $front = Zend_Controller_Front::getInstance();
        $front->registerPlugin(new Apps_Controller_Plugin_ModuleConfig());
    }

    protected function _initTranslator() {
        Zend_Registry::set(
                'Zend_Translate',
                new Zend_Translate(array(
                        'adapter' => 'array',
                        'content' => APPLICATION_PATH . '/lang/vi.php',
                        'locale'  => 'vi_VN'
                ))
        );

        Zend_Locale::setDefault('vi_VN');
    }


   protected function _initRoutes() {
    	$frontController = Zend_Controller_Front::getInstance();
    	$frontController->setControllerDirectory(APPLICATION_PATH . "/controllers");
    	$router = $frontController->getRouter();

    	$routePCategory = new Zend_Controller_Router_Route_Regex(
    	        'san-pham/(.+)-([0-9]*)\.html',
    	        array(
    	                'controller' => 'product',
    	                'action'     => 'category'
    	        ),
    	        array(
    	                1 => 'title',
    	                2 => 'id'
    	        ),
    	        'san-pham/%s-%d.html'
    	);
    	$router->addRoute('product-category', $routePCategory);

    	$routePDetail = new Zend_Controller_Router_Route_Regex(
    	        'chi-tiet/(.+)-([0-9]*)\.html',
    	        array(
    	                'controller' => 'product',
    	                'action'     => 'detail'
    	        ),
    	        array(
    	                1 => 'name',
    	                2 => 'id'
    	        ),
    	        'chi-tiet/%s-%d.html'
    	);
    	$router->addRoute('product-detail', $routePDetail);

    	$routePNew = new Zend_Controller_Router_Route_Regex(
    	        'san-pham-moi.html',
    	        array(
    	                'controller' => 'product',
    	                'action'     => 'new'
    	        ),
    	        array(),
    	        'san-pham-moi.html'
    	);
    	$router->addRoute('product-new', $routePNew);

    	$routePSaleOff = new Zend_Controller_Router_Route_Regex(
    	        'khuyen-mai.html',
    	        array(
    	                'controller' => 'product',
    	                'action'     => 'sale-off'
    	        ),
    	        array(),
    	        'khuyen-mai.html'
    	);
    	$router->addRoute('product-sale-off', $routePSaleOff);

    	$routeArticle = new Zend_Controller_Router_Route_Regex(
    	        'bai-viet/(.+)-([0-9]*)\.html',
    	        array(
    	                'controller' => 'article',
    	                'action'     => 'index'
    	        ),
    	        array(
    	                1 => 'title',
    	                2 => 't'
    	        ),
    	        'bai-viet/(.+)-([0-9]*)\.html'
    	);
    	$router->addRoute('article', $routeArticle);

    	$routeContract = new Zend_Controller_Router_Route_Regex(
    	        'lien-he.html',
    	        array(
    	                'controller' => 'contact',
    	                'action'     => 'index'
    	        ),
    	        array(),
    	        'lien-he.html'
    	);
    	$router->addRoute('contact', $routeContract);

    	$routeSiteMap = new Zend_Controller_Router_Route_Regex(
    	        'so-do-site.html',
    	        array(
    	                'controller' => 'site-map',
    	                'action'     => 'index'
    	        ),
    	        array(),
    	        'so-do-site.html'
    	);
    	$router->addRoute('site-map', $routeSiteMap);

    	$routeHome = new Zend_Controller_Router_Route_Regex(
    	        'trang-chu.html',
    	        array(
    	                'controller' => 'home',
    	                'action'     => 'index'
    	        ),
    	        array(),
    	        'trang-chu.html'
    	);
    	$router->addRoute('home', $routeHome);

  }

//     public function _initAcl() {
//     	$this->bootstrap('db');

//     	$frontController = Zend_Controller_Front::getInstance();
//     	$frontController->registerPlugin(new Apps_Controller_Plugin_Acl());
//     }
}